-------------------------------------------------------------------------------
--	 File name: init.lua
--		Author: Sploder
-- 		  Date: 03/04/2010
-- Description: This file contains the main body of code used by the
--				spellcardUse effect.
--
-------------------------------------------------------------------------------

AddCSLuaFile("init.lua")

EFFECT.TotalTime = 3.0
EFFECT.FirstPart = 0.75

-------------------------------------------------------------------------------
--	  Function: EFFECT:Init()
-- Description: This function is called when the effect is initialized.
-------------------------------------------------------------------------------
function EFFECT:Init()
	self.SecndPart = 1 - self.FirstPart

	self.time = CurTime() + self.TotalTime
	self.mat = Material("sprites/danmaku/spellcarduse")
end

-------------------------------------------------------------------------------
--	  Function: EFFECT:Think()
-- Description: This function is called every step.
-------------------------------------------------------------------------------
function EFFECT:Think()
	if (self.time > CurTime())
	then
		return true
	end
	return false
end

-------------------------------------------------------------------------------
--	  Function: EFFECT:Render()
-- Description: This function is called when the effect is rendered.
-------------------------------------------------------------------------------
function EFFECT:Render()
	local size = 512
	local first = self.TotalTime * self.FirstPart
	local secnd = self.TotalTime * self.SecndPart
	if ((CurTime() + secnd) < self.time)
	then
		self.mat:SetMaterialInt("$frame",
								math.Clamp(math.floor(41 - (41 * ((self.time - CurTime() - secnd) / first))), 0, 41))
	else
		self.mat:SetMaterialInt("$frame", 41)
		size = 512 * (self.time - CurTime()) / secnd
	end
	render.SetMaterial(self.mat)
	render.DrawSprite(self:GetPos(), size, size, Color(255, 0, 0, 255))
end